import 'package:casdon/common/state/common_net_status.dart';

class ServicePostOrderState {
  final CommonNetStatus status;
  final String? msg;
  final int version;
  final String? errorCode;

  final String? product;
  final String? expectTime;
  final String? contact;
  final String? phone;
  final String? location;
  final String? address;
  final String? memo;
  final String? channel;
  final String? buyDate;
  final String? orderNum;

  const ServicePostOrderState({
    this.status = CommonNetStatus.idle,
    this.msg,
    this.version = 0,
    this.errorCode,
    this.product,
    this.expectTime,
    this.contact,
    this.phone,
    this.location,
    this.address,
    this.memo,
    this.channel,
    this.buyDate,
    this.orderNum,
  });

  /// 快速构造不同状态
  factory ServicePostOrderState.idle() =>
      const ServicePostOrderState(status: CommonNetStatus.idle);

  factory ServicePostOrderState.loading([int version = 0]) =>
      ServicePostOrderState(status: CommonNetStatus.loading, version: version);

  factory ServicePostOrderState.success({String? msg, int version = 0}) =>
      ServicePostOrderState(
        status: CommonNetStatus.success,
        msg: msg,
        version: version,
      );

  factory ServicePostOrderState.failure({
    String? msg,
    String? errorCode,
    int version = 0,
  }) => ServicePostOrderState(
    status: CommonNetStatus.failure,
    msg: msg,
    errorCode: errorCode,
    version: version,
  );

  /// ✅ 完整的 copyWith
  ServicePostOrderState copyWith({
    CommonNetStatus? status,
    String? msg,
    int? version,
    String? errorCode,
    String? product,
    String? expectTime,
    String? contact,
    String? phone,
    String? location,
    String? address,
    String? memo,
    String? channel,
    String? buyDate,
    String? orderNum,
  }) {
    return ServicePostOrderState(
      status: status ?? this.status,
      msg: msg ?? this.msg,
      version: version ?? (this.version + 1),
      errorCode: errorCode ?? this.errorCode,
      product: product ?? this.product,
      expectTime: expectTime ?? this.expectTime,
      contact: contact ?? this.contact,
      phone: phone ?? this.phone,
      location: location ?? this.location,
      address: address ?? this.address,
      memo: memo ?? this.memo,
      channel: channel ?? this.channel,
      buyDate: buyDate ?? this.buyDate,
      orderNum: orderNum ?? this.orderNum,
    );
  }

  /// ✅ 完整 toString
  @override
  String toString() {
    return '''
ServicePostOrderState(
  status: $status,
  msg: $msg,
  version: $version,
  errorCode: $errorCode,
  product: $product,
  expectTime: $expectTime,
  contact: $contact,
  phone: $phone,
  location: $location,
  address: $address,
  memo: $memo,
  channel: $channel,
  buyDate: $buyDate,
  orderNum: $orderNum
)
''';
  }
}
